<?php

use Hyperf\Database\Schema\Schema;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Migrations\Migration;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('users', function (Blueprint $table) {
            $table->bigIncrements('id')->unsigned();
            $table->string('name', 100)->comment('用户名')->unique('name');
            $table->string('email')->comment('邮箱')->unique('email');
            $table->string('password')->comment('密码');
            $table->string('avatar', 500)->comment('头像url');
            $table->enum('role', ['user', 'author', 'admin'])->default('user')->comment('角色')->index('role');
            $table->enum('status', ['active', 'inactive', 'banned'])->default('active')->comment('状态')->index('status');
            $table->integer('points')->default(0)->comment('积分');
            $table->timestamp('last_login_at')->nullable()->comment('最后登录时间');
            $table->string('last_login_ip')->nullable();
            $table->timestamp('email_verified_at')->nullable();
            $table->timestamps();
            $table->index('created_at');

            $table->comment('用户表');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('users');
    }
}
